<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小黑记事本</title>
</head>

<body>
    <!-- 主体区域 -->
    <section id="todoapp">
        <!-- 输入框 -->
        <header class="header">
            <h1>小黑记事本</h1>
            <input v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="请输入任务"
                class="new-todo">
        </header>
        <!-- 列表区域 -->
        <section class="main">
            <ul class="todo-list">
                <li class="todo" v-for="(item,index) in list">
                    <div class="view">
                        <span class="index">{{index+1}}.</span>
                        <label>{{item}}</label>
                        <button class="destroy" @click="remove(index)">删除</button>
                    </div>
                </li>
            </ul>
            <!-- 统计和清空 -->
            <footer class="footer">
                <span class="todo-count" v-if="list.length!=0">
                    <strong>{{list.length}}items left</strong>
                </span>
                <button v-show="list.length!=0" class="clear-completed" @click="clear">
                    Clear
                </button>
            </footer>
        </section>
        <!-- 底部 -->
        <footer class="info">
            <p>
                <a href="http://www.itheima.com/"><img src="http://www.itheima.com/images/logo.png" alt=""></a>
            </p>
        </footer>
    </section>


    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</body>
<script>
    var app = new Vue({
        el: "#todoapp",
        data: {
            list: ["写代码", "吃饭饭", "睡觉觉"],
            inputValue: "好好学习,天天向上",

        },
        methods: {
            add: function () {
                this.list.push(this.inputValue);
            },
            remove: function (index) {
                console.log("删除");
                console.log(index);
                this.list.splice(index, 1);
            },
            clear: function () {
                this.list = [];
            }
        }
    })
</script>

<style>
    * {
        padding: 0;
        margin: 0;
    }

    #todoapp {
        width: 600px;
        margin: 5px auto;
        box-shadow: 0px 3px 10px 2px rgba(0, 0, 0, .1);

    }

    .header {
        font: normal 200 34px '微软雅黑';
        color: rgb(182, 182, 182);
        text-align: center;
        padding-top: 100px;
        padding-bottom: 10px;
    }

    .new-todo {
        width: 100%;
        height: 40px;
        padding-left: 10px;
        color: rgb(88, 88, 88);
        box-sizing: border-box;
        border: 1px solid rgb(236, 236, 236);
        /*这里之前宽写成100%就出现对不齐的问题*/
    }

    .new-todo:focus {
        outline: none;
    }

    .footer {
        position: relative;
        width: 100%;
        height: 40px;
        box-sizing: border-box;
        /*border-box你想要设置的边框和内边距的值是包含在width内的.不包含margin*/
        border: 1px solid rgb(236, 236, 236);
        background-color: white;

    }

    .footer span {
        font-size: 12px;
        color: rgb(131, 131, 131);
        float: leftr;
        line-height: 40px;
    }

    .reft {
        margin-left: 10px;
    }

    .right {
        margin-left: 170px;
    }

    .todo {
        list-style: none;
        font-size: 14px;
        font-family: '微软雅黑';
        color: rgb(88, 88, 88);
        box-sizing: border-box;
        width: 100%;
        height: 40px;
        line-height: 40px;
        border: 1px solid rgb(236, 236, 236);
        background-color: white;
    }

    .view {
        position: relative;
        margin-left: 10px;
    }

    .view label {
        width: 200px;
        height: 40px;
        position: absolute;
        overflow: hidden;
        /* 超出的文本隐藏*/
        text-overflow: ellipsis;
        /* 溢出用省略号显示*/
        white-space: nowrap;
        /* 溢出不换行*/
    }

    .destroy {
        position: absolute;
        right: 10px;
        top: 9px;
        font-size: 12px;
        font-family: '微软雅黑';
        /* outline: none; */
        border: 1px solid rgb(236, 236, 236);
        color: rgb(255, 111, 111);
        /* display: none; */
    }

    .view:hover .destroy {
        /*这里的.destroy和前面的要有空格，不然奏效*/
        display: block;
    }

    .reft strong {
        font-weight: 400;
    }

    .footer button {
        position: absolute;
        right: 10px;
        top: 9px;
        background-color: white;
        border: 0px;
        outline: none;
        /*去掉选中按钮是边框的颜色*/
        font-size: 12px;
        font-family: '微软雅黑';
        color: rgb(131, 131, 131);
    }
</style>

</html>